//项目中需要用到的全局方法
window.Global = 
{
    
    //获取角度
     getDegree:function(p1, p2)
     {
         var o = p2.x - p1.x;
         var a = p2.y - p1.y;
         var degree = Math.atan(o / a) * 180 / Math.PI;
         if(a<0)
         {
             degree = (o < 0) ? 180 + Math.abs(degree) : 180 - Math.abs(degree);
         }
         return degree;
     },
     
     
    //鱼类数据
     fishData:
     [
         {coin:1, captureRate:0.25, minSpeed:0.5, maxSpeed:1.2},  
         {coin:5, captureRate:0.15, minSpeed:0.5, maxSpeed:1.2},  
         {coin:10, captureRate:0.12, minSpeed:0.5, maxSpeed:1.2},  
         {coin:20, captureRate:0.10, minSpeed:0.5, maxSpeed:1.2},  
         {coin:30, captureRate:0.09, minSpeed:0.5, maxSpeed:0.8},  
         {coin:50, captureRate:0.08, minSpeed:0.5, maxSpeed:0.8},  
         {coin:70, captureRate:0.07, minSpeed:0.5, maxSpeed:0.8},  
         {coin:100, captureRate:0.03, minSpeed:0.5, maxSpeed:0.6},  
         {coin:200, captureRate:0.01, minSpeed:0.5, maxSpeed:0.6},  
     ],

     //随机最大角度与最小角度之间的值
     getRandomRotation:function(maxRotation,minRotation){
         return minRotation+Math.random()*(maxRotation-minRotation)+1;

     },

      //随机最大速度与最小速度之间的值
      getRandomSpeed:function(maxSpeed,minSpeed){
        return minSpeed+Math.random()*(maxSpeed-minSpeed)+1;

    },
    
    //添加节点到舞台并返回该节点及父类对象
    //showNode:当年前节点，className：节点上绑定的脚本，parent：当前节点的父节点，vx, vy：当前节点绑定到父节点上之后的坐标设置
     getClassAndAdd:function(showNode, className, parent, vx, vy)
     {
         //实例化节点
         var tempNode = cc.instantiate(showNode);
         var tempClass = tempNode.getComponent(className);
         parent.addChild(tempNode);  
         tempNode.x = vx;
         tempNode.y = vy;
         //返回的是两个参数，一个参数tNode是当前节点，一个参数tClass是当前节点绑定的脚本，调用脚本里面的函数
         return {tNode: tempNode, tClass:tempClass};
     },

    //判断是否出屏幕
     isOutOfScreen:function(node)
     {
       var w = cc.winSize.width >> 1, h = cc.winSize.height >> 1,
           nw = node.width >> 1, nh = node.height >> 1;
       return(node.x + nw < -w 
             ||node.x  - nw > w
             ||node.y < -h -nh
             ||node.y > h + nh);
     },
    
    //删除节点
     destroyNode:function(node)
     {
         if(node && node.parent)
         {
             node.destroy();
             node.parent.removeChild(node);
         }
     },
    
};